home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Whiteline: delta
/
whiteline CD Series - delta.iso
/
tools
/
utils
/
twtcp122
/
pktdrv
/
pktdlink
/
pktqueue.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-11-25
|
2KB
|
90 lines
/********************************************************************/
/* */
/* Packet driver for D-LINK ethernet controller */
/* */
/* Copyleft by P. Mayer, 1992 TU-Vienna IAEE */
/* All rights reserved */
/* */
/********************************************************************/
#include "nicmem.h"
#include "pktqueue.h"
#include <tos.h>
#ifndef NULL
#define NULL (void *)0L
#endif
#define FALSE 0
#define TRUE 1
#define DEBUGPKT
#define noDEBUG
extern long p_disint(void);
extern long p_enabint(void);
PKTPOOL *p_init(int npkt,PKTPOOL *p_pool,PKTBUF *p_buf)
{
register int i;
if(!p_pool) return(NULL);
p_pool->p_get = p_pool->p_put = 0;
p_pool->p_nbuf = npkt;
for(i=0; i<npkt; i++)
{
p_pool->p_tab[i].p_occupied = FALSE;
p_pool->p_tab[i].p_pkt = p_buf+i;
}
return(p_pool);
}
PKTBUF *ap_getpkt(u_short protocol, PKTPOOL *p_pool)
{
PKTBUF *pkt;
p_disint();
pkt=p_getpkt(protocol,p_pool);
p_enabint();
return(pkt);
}
PKTBUF *p_getpkt(u_short protocol, PKTPOOL *p_pool)
{
register int i;
if(!p_pool) return(NULL);
i = p_pool->p_get;
if(p_pool->p_tab[i].p_occupied) return(NULL);
p_pool->p_get++;
if(p_pool->p_get >= p_pool->p_nbuf) p_pool->p_get = 0;
p_pool->p_tab[i].p_occupied = protocol;
return(p_pool->p_tab[i].p_pkt);
}
int ap_putpkt(PKTPOOL *p_pool,PKTBUF *pkt)
{
int r;
p_disint();
r=p_putpkt(p_pool,pkt);
p_enabint();
return(r);
}
int p_putpkt(PKTPOOL *p_pool,PKTBUF *pkt)
{
register int i;
if(!p_pool) return(FALSE);
i = p_pool->p_put;
if(!p_pool->p_tab[i].p_occupied)
{
Cconws("DLINKDRV: Packet already in queue\r");
return(FALSE);
}
p_pool->p_put++;
if(p_pool->p_put >= p_pool->p_nbuf) p_pool->p_put = 0;
p_pool->p_tab[i].p_pkt = pkt;
p_pool->p_tab[i].p_occupied = FALSE;
return(TRUE);
}